package com.teaboot.springbootsample.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = DataSourceProperties.MYSQLDB_PREFIX, ignoreUnknownFields = false)
public class DataSourceProperties {

    //对应配置文件里的配置键
    public final static String MYSQLDB_PREFIX="mysqldb.datasource";

    private String driverClassName ="com.mysql.jdbc.Driver";

    private String url;
    private String username;
    private String password;

    private int maxActive = 20;  //最大连接池数量
    private int maxWait = 10000; //获取连接时最大等待时间，单位毫秒
    private int minIdle = 8;     //最小连接池数量
    private int initialSize = 8; //初始化时建立物理连接的个数

    private String validationQuery = "select 'x'";  //用来检测连接是否有效的sql

    private boolean testOnBorrow = false;  //申请连接时执行validationQuery检测连接是否有效，做了这个配置会降低性能
    private boolean testOnReturn = false;  //归还连接时执行validationQuery检测连接是否有效，做了这个配置会降低性能
    private boolean testWhileIdle = true;  //建议配置为true，不影响性能，并且保证安全性。申请连接的时候检测，如果空闲时间大于timeBetweenEvictionRunsMillis，执行validationQuery检测连接是否有效。
    private boolean keepAlive = true;      //空闲时间超过minEvictableIdleTimeMillis，是否执行keepAlive操作  https://github.com/alibaba/druid/wiki/KeepAlive_cn

    private int minEvictableIdleTimeMillis = 300000; //连接保持空闲而不被驱逐的最长时间

    private String filters = ""; //通过别名的方式配置扩展插件 https://github.com/alibaba/druid/wiki/DruidDataSource%E9%85%8D%E7%BD%AE%E5%B1%9E%E6%80%A7%E5%88%97%E8%A1%A8

    public String getDriverClassName() {
        return driverClassName;
    }

    public void setDriverClassName(String driverClassName) {
        this.driverClassName = driverClassName;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getMaxActive() {
        return maxActive;
    }

    public void setMaxActive(int maxActive) {
        this.maxActive = maxActive;
    }

    public int getMaxWait() {
        return maxWait;
    }

    public void setMaxWait(int maxWait) {
        this.maxWait = maxWait;
    }

    public int getMinIdle() {
        return minIdle;
    }

    public void setMinIdle(int minIdle) {
        this.minIdle = minIdle;
    }

    public int getInitialSize() {
        return initialSize;
    }

    public void setInitialSize(int initialSize) {
        this.initialSize = initialSize;
    }

    public String getValidationQuery() {
        return validationQuery;
    }

    public void setValidationQuery(String validationQuery) {
        this.validationQuery = validationQuery;
    }

    public boolean isTestOnBorrow() {
        return testOnBorrow;
    }

    public void setTestOnBorrow(boolean testOnBorrow) {
        this.testOnBorrow = testOnBorrow;
    }

    public boolean isTestOnReturn() {
        return testOnReturn;
    }

    public void setTestOnReturn(boolean testOnReturn) {
        this.testOnReturn = testOnReturn;
    }

    public boolean isTestWhileIdle() {
        return testWhileIdle;
    }

    public void setTestWhileIdle(boolean testWhileIdle) {
        this.testWhileIdle = testWhileIdle;
    }

    public boolean isKeepAlive() {
        return keepAlive;
    }

    public void setKeepAlive(boolean keepAlive) {
        this.keepAlive = keepAlive;
    }

    public int getMinEvictableIdleTimeMillis() {
        return minEvictableIdleTimeMillis;
    }

    public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
        this.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
    }

    public String getFilters() {
        return filters;
    }

    public void setFilters(String filters) {
        this.filters = filters;
    }
}

